/**
 * 修改密码
 * @author Qasim <15750783791@163.com>
 * @version 2016/10/31
 */
document.addEventListener('plusready' , ready , false);
var self = memberInfo = '';
function ready(){
	self = plus.webview.currentWebview(); 
	memberInfo = plus.storage.getItem('memberInfo'); 
	memberInfo = $.parseJSON(memberInfo);
	//修改密码 
	$('.update_pass').on('click' , function(){
		var pass = $('input[name=pass]').val() , 
			new_pass = $('input[name=new_pass]').val() , 
			new_repass = $('input[name=new_repass]').val();
		if(!pass.trim() || !new_pass.trim() ||!new_repass.trim()){
			toast('输入框不能为空'); return;
		}
		if(new_pass !== new_repass){
			toast('两次密码不一致'); return;
		}
		
		if(pass === new_pass){ 
			toast('新密码与原密码相同'); return;
		}
		console.log(memberInfo.aid + ',' + pass + ',' +new_pass)
		$.ajax({
			url : apiRoot + '/Home/Member/updatePassword/' , 
			type : 'post' , 
			data : {
				aid : memberInfo.aid,
				pass : pass , 
				new_pass : new_pass 
			} , 
			beforeSend : function(){
				plus.nativeUI.showWaiting('修改中...');
			},
			complete:function(){
				plus.nativeUI.closeWaiting();
			},
			success : function(data){
				if(data == -1){
					toast('原密码错误');
				}else{
					toast('修改成功');
					plus.storage.removeItem('memberInfo');
 					openNewPage('index.html')
				}
			} , 
			error : function(e){
				errorPrompt(e);
			}
		})
	})
	
}
